#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;

class Solution
{
public:
    int longestConsecutive(vector<int>& nums)
    {
        unordered_set<int> temp_nums(nums.begin(), nums.end());
        int ans = 0;

        for (auto num : temp_nums)
        {
            if (temp_nums.find(num - 1) == temp_nums.end())
            {
                int current_num = num;
                int length = 1;

                while (temp_nums.find(current_num + 1) != temp_nums.end())
                {
                    ++current_num;
                    ++length;
                }
                ans = max(ans, length);
            }
        }

        return ans;
    }
};

int main()
{
    vector<int> v{ 0,3,7,2,5,8,4,6,0,1 };
    cout << Solution().longestConsecutive(v);

    return 0;
}